//
//  WithdrawalViewController.m
//  dyseller
//
//  Created by 红喇叭 on 2017/8/16.
//  Copyright © 2017年 红喇叭. All rights reserved.
//

#import "WithdrawalViewController.h"

@interface WithdrawalViewController ()<UITextFieldDelegate>
@property (strong, nonatomic) UITextField *moneyNum;
@property (strong, nonatomic) UILabel *yueMoney;

@end

@implementation WithdrawalViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNavTitle:@"提现申请" titleColor:[UIColor blackColor] font:font17];
    [self.backBtn setImage:[UIImage imageNamed:@"caiwu_nav_icon_default.png"] forState:UIControlStateNormal];
    [self initViewLayout];
    _yueMoney.text =  [NSString stringWithFormat:@"￥%@",_moneyStr];
    
}

- (void)initViewLayout{
    UIImageView *shadowImg = [[UIImageView alloc] init];
    shadowImg.userInteractionEnabled = YES;
    shadowImg.image = [UIImage imageNamed:@"tixian_label2_default_nor.png"];
    [self.view addSubview:shadowImg];
    shadowImg.sd_layout.leftSpaceToView(self.view, GETWITH(28)).rightSpaceToView(self.view, GETWITH(28)).topSpaceToView(self.view, 30).heightIs(101);
    
    UIImageView *backImg = [[UIImageView alloc] init];
    backImg.userInteractionEnabled = YES;
    
    backImg.image = [UIImage imageNamed:@"tixian_label_default_nor.png"];
    [self.view addSubview:backImg];
     backImg.sd_layout.leftSpaceToView(self.view, GETWITH(30)).rightSpaceToView(self.view, GETWITH(30)).topSpaceToView(self.view, 30.5).heightIs(100);
    
    UILabel *ktixian = [[UILabel alloc] init];
    ktixian.text = @"可提现金额";
    ktixian.font = [UIFont systemFontOfSize:15];
    ktixian.textColor = UIColorFromRGB(0x999999);
    [backImg addSubview:ktixian];
    ktixian.sd_layout.leftSpaceToView(backImg, GETWITH(30)).topSpaceToView(backImg, GETHEIGHT(44)).widthIs(80).autoHeightRatio(0);
    
    _yueMoney = [[UILabel alloc] init];
    _yueMoney.font = [UIFont fontWithName:@"PingFang-SC-Regular,ArialMT" size:27];
    _yueMoney.textColor = UIColorFromRGB(0X333333);
    _yueMoney.textAlignment = NSTextAlignmentRight;
    [backImg addSubview:_yueMoney];
    _yueMoney.sd_layout.centerYEqualToView(ktixian).rightSpaceToView(backImg, GETWITH(30)).autoHeightRatio(0).widthIs(100);
    
    UIView *lineView = [[UIView alloc] init];
    lineView.backgroundColor = [UIColor grayColor];
    [backImg addSubview:lineView];
    lineView.sd_layout.leftEqualToView(ktixian).rightEqualToView(_yueMoney).heightIs(0.5).topSpaceToView(_yueMoney, GETHEIGHT(20));
    
    UILabel *tishi = [[UILabel alloc] init];
    tishi.text = @"本次提现金额";
    tishi.font = [UIFont systemFontOfSize:15];
    tishi.textColor = UIColorFromRGB(0x999999);
    [backImg addSubview:tishi];
    tishi.sd_layout.leftSpaceToView(backImg, GETWITH(30)).topSpaceToView(lineView, GETHEIGHT(30)).widthIs(120).autoHeightRatio(0);
    
    _moneyNum = [[UITextField alloc] init];
    
    _moneyNum.placeholder = @"请输入";
    _moneyNum.delegate = self;
    _moneyNum.font = [UIFont fontWithName:@"PingFang-SC-Regular,ArialMT" size:27];
    _moneyNum.textColor = UIColorFromRGB(0X333333);
    _moneyNum.textAlignment = NSTextAlignmentRight;
    [backImg addSubview:_moneyNum];
    _moneyNum.sd_layout.heightIs(20).widthIs(100).rightSpaceToView(backImg, GETWITH(30)).centerYEqualToView(tishi);
    
    UIButton *tijiao = [UIButton buttonWithType:UIButtonTypeCustom];
    [tijiao setTitle:@"提交" forState:UIControlStateNormal];
    [tijiao setTitleColor:UIColorFromRGB(0Xffffff) forState:UIControlStateNormal];
    [tijiao addTarget:self action:@selector(tixian:) forControlEvents:UIControlEventTouchUpInside];
    [tijiao setBackgroundImage:[UIImage imageNamed:@"user_btn_default_nor.png"] forState:UIControlStateNormal];
    [self.view addSubview:tijiao];
    tijiao.sd_layout.topSpaceToView(shadowImg, GETHEIGHT(60)).centerXEqualToView(self.view).widthIs(GETWITH(690)).heightIs(GETHEIGHT(88));

    
}

- (void)tixian:(id)sender {
    if(_moneyNum.text.length < 1){
      [AlertUtils showToastWithMessage:@"请输入提现金额" inView:self.view hideAfterDelay:2.0 beIndeter:NO];
        return;
    }
    if([_moneyNum.text floatValue] > [_moneyStr floatValue]){
        [AlertUtils showToastWithMessage:@"可提现金额不足" inView:self.view hideAfterDelay:2.0 beIndeter:NO];
        return;
    }
    [self loadingData];
}

- (void)loadingData{
    __weak typeof(self)weakself = self;
    [[PPHttpRequsetData shareInstance] requestStyle:Request_POST URL:@"/ShopApi/Finance/getCash" parameter:@{@"money":_moneyNum.text} successBlock:^(PPHttpRequest *request, id responseObj) {
        
        [AlertUtils showToastWithMessage:@"提现申请成功" inView:self.view hideAfterDelay:2.0 beIndeter:NO];
        [weakself performSelector:@selector(back) withObject:nil afterDelay:2];
       
    } failBlock:^(PPHttpRequest *request, NSString *errMsg) {
        [AlertUtils showToastWithMessage:errMsg inView:self.view hideAfterDelay:2.0 beIndeter:NO];
    }];
}

- (void)back{
    [self.navigationController popViewControllerAnimated:YES];
}
@end
